package com.my.vertx.http.websocket;

import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;

/**
 * Vertx websocket
 *
 * <p>
 *     <a href="https://vertx.io/docs/vertx-core/java/#_websockets">参考: Vertx- Websocket</a>
 * </p>
 *
 * @author: marshal
 * @date: 2023-04-13 9:48
 */
public class VertxWebsocketServerTest {
    public static void main(String[] args) {
        // 创建vertx对象
        Vertx vertx = Vertx.vertx();
        // 创建HttpServerOptions
        HttpServerOptions options = new HttpServerOptions()
                .setPort(9600)
                .setHost("127.0.0.1")
                .setLogActivity(true);
        // 创建HttpServer
        HttpServer httpServer = vertx.createHttpServer(options);
        // 微波socket
        httpServer.webSocketHandler(websocket -> {
            System.out.println("Connected!");
            websocket.accept();
        });
    }
}
